var Render = 
{
    event : [],
    addEvent(doFun){
        var it= this;
        it.event.push(doFun);
    },
    clear(){
        ctx.clearRect(0,0,w,h)
    },
    draw(){
        var it = this;
        it.clear();
        // draw bg
        ctx.beginPath();
        ctx.drawImage(G.res['g_front'].el,0,0,w,h)
        ctx.closePath();

        // draw add event
        for(var x in it.event){
            typeof it.event[x] == "function" && it.event[x]();
        }

        // draw player
        for(var x in Player){
            var p = Player[x];
            var skill = p.skill[p.stat];
            var img = skill.img,imgpos = [skill.map[0],skill.map[1],skill.map[0]*skill.i,0],ppos = [p.pos[0],190-p.pos[1]-imgpos[1]];
            ctx.beginPath();
            if(p.faceTo == "left"){
                ctx.scale(-1,1);
                ctx.translate(-2*ppos[0] - imgpos[0],0);
            }
            ctx.drawImage(G.res[img].el,imgpos[2],imgpos[3],imgpos[0],imgpos[1],ppos[0],ppos[1],imgpos[0],imgpos[1]);
            if(p.faceTo == "left"){
                ctx.translate(2*ppos[0] + imgpos[0],0);
                ctx.scale(-1,1);
            }
            ctx.closePath();
        }

        // draw skillBall

        
    },
    drawFps(){
        var it = this;
        var opt = 
        {
            x  : 0,
            y  : 0,
            w  :150,
            h  : 80
        }
        ctx.beginPath();
        ctx.fillStyle = "rgba(0,0,0,.4)";
        ctx.fillRect(opt.x,opt.y,opt.w,opt.h);
        ctx.closePath();
        if(Timer._fps.list.length){
            var list = Timer._fps.list.slice(-100,-1),l = list.length,x0 = ~~((opt.w-l)/2 + opt.x)+0.5,y0 = opt.y+opt.h;
            for(var x in list){
                ctx.beginPath();
                ctx.moveTo(x0,y0);
                ctx.lineTo(x0++,y0-list[x]);
                ctx.strokeStyle = "rgba(15,211,34,.5)";
                ctx.stroke();
                ctx.closePath();
            }
        }
        
    }

    
}